package com.hzz.service.analysis;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzz.api.analysis.IAnalysisRiverSupervisorService;
import com.hzz.dao.analysis.IAnalysisRiverSupervisorDao;
import com.hzz.dto.analysis.AnalysisRiverSupervisorDto;
import com.hzz.entity.analysis.AnalysisRiverSupervisor;
import com.hzz.framework.SysErrorCode;
import com.hzz.framework.exception.ServiceException;
import com.hzz.framework.service.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class AnalysisRiverSupervisorService extends BaseService implements IAnalysisRiverSupervisorService {
    @Autowired
    IAnalysisRiverSupervisorDao analysisRiverSupervisorDao;

    @Override
    public PageInfo analysisRiverSupervisorAreaPage(AnalysisRiverSupervisorDto dto) {
        PageInfo pageInfo = null;
        try {
            AnalysisRiverSupervisor entity = copyTo(dto, AnalysisRiverSupervisor.class);
            PageHelper.startPage(PN(dto.getPageNum()), PS(dto.getPageSize()));
            List list = analysisRiverSupervisorDao.analysisRiverSupervisorAreaName(entity);
            pageInfo = new PageInfo(list);
            pageInfo.setList(pageInfo.getList());
        } catch (Exception e) {
            log.error("河长统计分析-各级河长数量 分页。异常!", e);
            throw new ServiceException(SysErrorCode.defaultError, e);
        }
        return pageInfo;
    }

    @Override
    public List<Map> analysisRiverSupervisorAreaName(AnalysisRiverSupervisorDto dto) {
        List<Map> results = null;
        try {
            AnalysisRiverSupervisor entity = copyTo(dto, AnalysisRiverSupervisor.class);
            results = analysisRiverSupervisorDao.analysisRiverSupervisorAreaName(entity);
        } catch (Exception e) {
            log.error("河长统计分析-各级河长数量 列表。异常!", e);
            throw new ServiceException(SysErrorCode.defaultError, e);
        }
        return results;
    }

    @Override
    public List<Map> analysisRiverSupervisorAreaLevel(AnalysisRiverSupervisorDto dto) {
        List<Map> results = null;
        try {
            AnalysisRiverSupervisor entity = copyTo(dto, AnalysisRiverSupervisor.class);
            results = analysisRiverSupervisorDao.analysisRiverSupervisorAreaLevel(entity);
        } catch (Exception e) {
            log.error("河长统计分析-各级河长数量。异常!", e);
            throw new ServiceException(SysErrorCode.defaultError, e);
        }
        return results;
    }

    @Override
    public List<Map> analysisRiverSupervisorChildAreaName(AnalysisRiverSupervisorDto dto) {
        List<Map> results = null;
        try {
            AnalysisRiverSupervisor entity = copyTo(dto, AnalysisRiverSupervisor.class);
            results = analysisRiverSupervisorDao.analysisRiverSupervisorChildAreaName(entity);
        } catch (Exception e) {
            log.error("河长统计分析-次级行政区河长数量。异常!", e);
            throw new ServiceException(SysErrorCode.defaultError, e);
        }
        return results;
    }

    @Override
    public Integer analysisRiverSupervisor(AnalysisRiverSupervisorDto dto) {
        Integer result = null;
        try {
            AnalysisRiverSupervisor entity = copyTo(dto, AnalysisRiverSupervisor.class);
            result = analysisRiverSupervisorDao.analysisRiverSupervisor(entity);
        } catch (Exception e) {
            log.error("河长统计分析-次级行政区河长数量。异常!", e);
            throw new ServiceException(SysErrorCode.defaultError, e);
        }
        return result;
    }

}